﻿using Google.Protobuf;
using System;
using System.Collections.Generic;
using System.Text;
using Cemit.Awaiter;
using Cemit.PolyProto;
using Newtonsoft.Json;

namespace Cemit.PolyServer
{
    public static class ClientStateSendExtensions
    {
        public static ClientState SendDynamicMsg(this ClientState client, string key, dynamic data)
        {
            client.server.Send(client, new D { Key = key, Data = JsonConvert.SerializeObject(new { D = data }) });
            return client;
        }

        public static ClientState Send(this ClientState client, IMessage message)
        {
            client.server.Send(client, message);
            return client;
        }

        public static AsyncAction<T> Get<T>(this ClientState client, IMessage message) where T : IMessage, new()
        {
            return client.server.Get<T>(client, message);
        }
    }
}
